import java.io.*;
import java.util.HashMap;
import java.util.StringTokenizer;

public class 四个选项 {
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static int[] arr = new int[5];
    public static boolean[][] vis = new boolean[13][13];
    public static int[] path = new int[13];
    public static int m,ans;
    public static void main(String[] args) throws IOException {
        for (int i = 1; i <= 4; i++) {
            arr[i] = in.nextInt();
        }
        m = in.nextInt();
        ans = 0;
        while (m-- > 0) {
            int a = in.nextInt();
            int b = in.nextInt();
            vis[a][b] = vis[b][a] = true;
        }
        dfs(1);
        out.print(ans);
        out.close();
    }

    private static void dfs(int pos) {
        if (pos == 13) {
            ans++;
            return;
        }
        for (int i = 1; i <= 4; i++) {
            if (arr[i] == 0) continue;
            if (!isSame(i,pos)) continue;
            path[pos] = i;
            arr[i]--;
            dfs(pos + 1);
            arr[i]++;
        }
    }

    private static boolean isSame(int i, int pos) {
        for (int j = 1; j < pos; j++) {
            if (vis[pos][j] && i != path[j]) {
                return false;
            }
        }
        return true;
    }


    public static class Read // 自定义快速读入
    {
        StringTokenizer st = new StringTokenizer("");
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String next() throws IOException
        {
            while(!st.hasMoreTokens())
            {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        String nextLine() throws IOException
        {
            return bf.readLine();
        }

        int nextInt() throws IOException
        {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException
        {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException
        {
            return Double.parseDouble(next());
        }
    }
}
